package com.tocici.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import com.tocici.domain.vo.UserBehaviorVo;
import com.tocici.domain.bo.UserBehaviorBo;
import com.tocici.service.IUserBehaviorService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 用户行为
 *
 * @author zeratul
 * @date 2025-03-02
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/music/behavior")
public class UserBehaviorController extends BaseController {

    private final IUserBehaviorService userBehaviorService;

    /**
     * 查询用户行为列表
     */
    @SaCheckPermission("music:behavior:list")
    @GetMapping("/list")
    public TableDataInfo<UserBehaviorVo> list(UserBehaviorBo bo, PageQuery pageQuery) {
        return userBehaviorService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户行为列表
     */
    @SaCheckPermission("music:behavior:export")
    @Log(title = "用户行为", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(UserBehaviorBo bo, HttpServletResponse response) {
        List<UserBehaviorVo> list = userBehaviorService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户行为", UserBehaviorVo.class, response);
    }

    /**
     * 获取用户行为详细信息
     *
     * @param behaviorId 主键
     */
    @SaCheckPermission("music:behavior:query")
    @GetMapping("/{behaviorId}")
    public R<UserBehaviorVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long behaviorId) {
        return R.ok(userBehaviorService.queryById(behaviorId));
    }

    /**
     * 新增用户行为
     */
    @SaCheckPermission("music:behavior:add")
    @Log(title = "用户行为", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody UserBehaviorBo bo) {
        return toAjax(userBehaviorService.insertByBo(bo));
    }

    /**
     * 修改用户行为
     */
    @SaCheckPermission("music:behavior:edit")
    @Log(title = "用户行为", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody UserBehaviorBo bo) {
        return toAjax(userBehaviorService.updateByBo(bo));
    }

    /**
     * 删除用户行为
     *
     * @param behaviorIds 主键串
     */
    @SaCheckPermission("music:behavior:remove")
    @Log(title = "用户行为", businessType = BusinessType.DELETE)
    @DeleteMapping("/{behaviorIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] behaviorIds) {
        return toAjax(userBehaviorService.deleteWithValidByIds(List.of(behaviorIds), true));
    }



}
